from django.test import TestCase
from google.appengine.ext.db import BadValueError
from accomplishment.models import Accomplishment

test_title = u"test_title"
title_attr_name = "title"

class TestAccomplishment(TestCase):  

    def setUp(self):
        self.accomplishment = Accomplishment(title = test_title)

    def test_should_instantiate_object_of_its_own_type(self):  
        accomplishment_type = type(self.accomplishment) 
        self.failUnlessEqual(accomplishment_type, Accomplishment, "Accomplishment \
model is not being instantiated")
    
    def test_should_have_title_attribute(self):
        has_title = hasattr(self.accomplishment, title_attr_name)
        self.failUnless(has_title, "Accomplishment model lacks a title attribute")
        
    def test_title_can_store_stringlike_value(self):
        title = self.accomplishment.title
        self.failUnlessEqual(title, test_title, "Accomplishment \
model is storing the title incorrectly")
        
    def test_title_is_required(self):
        self.failUnlessRaises(BadValueError, Accomplishment)
        
    def test_unicode_representation_of_accomplishment_is_the_title(self):
        unicode_representation = unicode(self.accomplishment)
        self.failUnlessEqual(test_title, unicode_representation, "Unicode representation \
of accomplishment is not the title")
        